package com.example.wechar.config;

import com.example.wechar.context.ContextMessageFactory;
import com.example.wechar.service.message.ImageMessageServiceImpl;
import com.example.wechar.service.message.TextMessageServiceImpl;
import com.example.wechar.utils.MessageType;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MessageConfig {
    /**
     * spring核心bean容器
     */
    private ApplicationContext applicationContext;
    public MessageConfig(ApplicationContext applicationContext){
        this.applicationContext = applicationContext;
    }
    @Bean
    public ContextMessageFactory getContextMessageFactory(){
        ContextMessageFactory contextMessageFactory = new ContextMessageFactory();
        contextMessageFactory.builder(MessageType.IMAGE,applicationContext.getBean(ImageMessageServiceImpl.class));
        contextMessageFactory.builder(MessageType.TEXT,applicationContext.getBean(TextMessageServiceImpl.class));
        return contextMessageFactory;
    }
}

